function cleanString(input) {
  // 去除零宽字符和前后空格
  return input.replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
}

// 去除空格、无用换行符
function formatContent(content) {
  const paragraphs = content
    .split("\n")
    .filter((paragraph) => paragraph.trim() !== "");
  // 去除段落开头的空格
  const processedParagraphs = paragraphs.map((paragraph) => paragraph.trim());
  // 使用一个换行符连接段落
  return processedParagraphs.join("\n");
}

export function parseTitle(title) {
  if (title.indexOf(".docx") !== -1) {
    const fileName = title.substring(0, title.lastIndexOf("."));
    return cleanString(fileName);
  }
  return cleanString(title);
}

export function processContent(content) {
  let cleanedContent = formatContent(content);
  // 去除附件
  const index = content.indexOf("附件：");
  if (index !== -1) {
    cleanedContent = content.substring(0, index).trim();
  }

  // 去除 人民日报 后面的部分
  const index_people_journal = content.indexOf("《 人民日报 》")
  if (index_people_journal !== -1) {
    cleanedContent = content.substring(0, index_people_journal).trim();
  }

  return cleanedContent;
}
